var WPMT_DoctorEvaluation_ORM = /** @class */ (function () {
    function WPMT_DoctorEvaluation_ORM(workid) {
        this.data = {
            dbConn: TSLobsterAPI.Program.GetDbConn(),
            WorkId: 1
        };
        this.WPMT_DoctorEvaluation = {
            "model": {
                "ID": 0,
                "RecordId": 0,
                "OrderNo": "",
                "MPUserId": "",
                "EmpId": 0,
                "PatientId": 0,
                "Satisfaction": "",
                "EvaluateContent": "",
                "Status": 0,
                "EvaluateTime": "yyyy-MM-dd",
                "OperateTime": "yyyy-MM-dd",
                "WorkId": 0,
                "ReplyContent": "",
                "ReplyTime": "yyyy-MM-dd",
                "ReplyEmpId": 0,
                "DocName": "",
                "PatName": ""
            },
            "tablename": "WPMT_DoctorEvaluation",
            "key": "ID",
            "val": "0",
            "objval": {},
            "query": {},
            "where": "",
            "pageinfo": {},
            "WorkId": 1
        };
        this.data.WorkId = workid;
        this.WPMT_DoctorEvaluation.WorkId = workid;
    }
    WPMT_DoctorEvaluation_ORM.prototype.Save = function (model) {
        this.WPMT_DoctorEvaluation.objval = model;
        return TSLobsterAPI.DbHelper.SaveModel(this.data.dbConn, this.WPMT_DoctorEvaluation);
    };
    WPMT_DoctorEvaluation_ORM.prototype.GetList = function (where) {
        return TSLobsterAPI.OrmMsSql.GetListModel(this.data.dbConn, this.WPMT_DoctorEvaluation);
    };
    return WPMT_DoctorEvaluation_ORM;
}());

//author:kakake

//author:kakake
var tsevaluationDao = /** @class */ (function () {
    function tsevaluationDao(workid) {
        this.data = {
            dbConn: TSLobsterAPI.Program.GetDbConn(),
            WorkId: 1
        };
        this.data.WorkId = workid;
    }
    /**
     * 获取问诊记录
     */
    tsevaluationDao.prototype.getmedrecord = function (id) {
        var strsql = "select * from WPMT_RegisteredPayment where Id=@id";
        return TSLobsterAPI.DbHelper.DbGetJsonObject(this.data.dbConn, strsql, { id: id });
    };
    /**
     * 获取评价
     */
    tsevaluationDao.prototype.getevaluation = function (RecordId) {
        var strsql = "SELECT * FROM WPMT_DoctorEvaluation where RecordId=@RecordId";
        return TSLobsterAPI.DbHelper.DbGetJsonObject(this.data.dbConn, strsql, { RecordId: RecordId });
    };
    /**
     * 获取待处理评价
     */
    tsevaluationDao.prototype.getevaluationpage = function (searchkey, status, pageInfo) {
        var strsql = "SELECT a.* FROM WPMT_DoctorEvaluation a \
                    where a.workid=@workid and a.DocName LIKE @searchkey and a.PatName like @searchkey";
        if (status != -1) {
            strsql += " and a.Status=@status";
        }
        var dbparam = {
            workid: this.data.WorkId,
            searchkey: '%' + searchkey + '%',
            status: status
        };
        return TSLobsterAPI.DbHelper.DbGetJsonData(this.data.dbConn, strsql, dbparam, pageInfo);
    };
    /**
     * 保存回复内容
     */
    tsevaluationDao.prototype.savereplycontent = function (ID, ReplyContent) {
        var strsql = "update WPMT_DoctorEvaluation set ReplyContent=@ReplyContent,ReplyTime=GETDATE(),ReplyEmpId=@ReplyEmpId where ID=@ID";
        var dbparam = {
            ID: ID,
            ReplyContent: ReplyContent,
            ReplyEmpId: TSLobsterAPI.Program.GetSSOUserId()
        };
        TSLobsterAPI.DbHelper.DbExecuteUpdate(this.data.dbConn, strsql, dbparam);
    };
    /**
     * 发布，取消发布
     */
    tsevaluationDao.prototype.stopevaluation = function (ID, status) {
        var strsql = "update WPMT_DoctorEvaluation set status=@status where ID=@ID";
        TSLobsterAPI.DbHelper.DbExecuteUpdate(this.data.dbConn, strsql, { ID: ID, status: status });
    };
    /**
     * 医生信息界面，显示点赞最多的评价
     */
    tsevaluationDao.prototype.getevaluationtopone = function (doctId) {
        var strsql = "select top 1 * from WPMT_DoctorEvaluation where workid=@workid and status=1 and EmpId=@doctId order by givecount desc";
        return TSLobsterAPI.DbHelper.DbGetJsonData(this.data.dbConn, strsql, { workid: this.data.WorkId, doctId: doctId });
    };
    /**
     * 查询医生全部评价
     */
    tsevaluationDao.prototype.getevaluationbydoctor = function (doctId, pageInfo) {
        var strsql = "select  * from WPMT_DoctorEvaluation where workid=@workid and status=1 and EmpId=@doctId";
        return TSLobsterAPI.DbHelper.DbGetJsonData(this.data.dbConn, strsql, { workid: this.data.WorkId, doctId: doctId }, pageInfo);
    };
    /**
     * 更新评价点赞数
     */
    tsevaluationDao.prototype.updateevaluationgivecount = function (id) {
        var strsql = "update WPMT_DoctorEvaluation set givecount=isnull(givecount,0)+1 where ID=@id";
        TSLobsterAPI.DbHelper.DbExecuteUpdate(this.data.dbConn, strsql, { id: id });
        strsql = "select givecount from WPMT_DoctorEvaluation where ID=@id";
        return TSLobsterAPI.DbHelper.DbExecuteQuery(this.data.dbConn, strsql, { id: id });
    };
    return tsevaluationDao;
}());

//author:kakake
var tsevaluationService = /** @class */ (function () {
    function tsevaluationService(workid) {
        this.data = {
            dbConn: TSLobsterAPI.Program.GetDbConn(),
            WorkId: 1
        };
        this.data.WorkId = workid;
    }
    return tsevaluationService;
}());

//author:kakake
/**
 * 医生评价处理
 */
var tsevaluationController = /** @class */ (function () {
    function tsevaluationController() {
        this.data = {
            dbConn: TSLobsterAPI.Program.GetDbConn(),
            WorkId: 1
        };
        this.data.WorkId = TSLobsterAPI.Program.GetWorkId();
        this.service = new tsevaluationService(this.data.WorkId);
        this.dao = new tsevaluationDao(this.data.WorkId);
    }
    /**
     * 获取问诊记录
     */
    tsevaluationController.prototype.getmedrecord = function () {
        var id = TSLobsterAPI.Program.RequestQuery("id") || '0';
        var data = this.dao.getmedrecord(parseInt(id));
        return { info: data };
    };
    /**
     * 获取评价
     */
    tsevaluationController.prototype.getevaluation = function () {
        var RecordId = TSLobsterAPI.Program.RequestQuery("RecordId") || '0';
        var data = this.dao.getevaluation(parseInt(RecordId));
        return { evaluation: data };
    };
    /**
     * 提交评价
     */
    tsevaluationController.prototype.saveevaluation = function () {
        var model = JSON.parse(TSLobsterAPI.Program.RequestBody());
        var evaluation = new WPMT_DoctorEvaluation_ORM(this.data.WorkId);
        var evaluationVal = {};
        evaluationVal.ID = model.ID;
        evaluationVal.RecordId = model.RecordId;
        evaluationVal.OrderNo = model.OrderNo;
        evaluationVal.MPUserId = TSLobsterAPI.Program.GetMPUserId();
        evaluationVal.EmpId = model.EmpId;
        evaluationVal.PatientId = model.PatientId;
        evaluationVal.Satisfaction = model.Satisfaction;
        evaluationVal.EvaluateContent = model.EvaluateContent;
        evaluationVal.Status = 0;
        evaluationVal.EvaluateTime = TSLobsterAPI.Utils.getCurrTime();
        evaluationVal.OperateTime = TSLobsterAPI.Utils.getCurrTime();
        evaluationVal.ReplyContent = "";
        evaluationVal.ReplyEmpId = 0;
        evaluationVal.ReplyTime = null;
        evaluationVal.DocName = model.DocName;
        evaluationVal.PatName = model.PatName;
        evaluation.Save(evaluationVal);
        return { result: true };
    };
    /**
     * 获取待处理评价
     */
    tsevaluationController.prototype.getevaluationpage = function () {
        var pageInfo = {
            key: "ID",
            page: TSLobsterAPI.Program.RequestQuery("page", "1"),
            perPage: TSLobsterAPI.Program.RequestQuery("limit", "10"),
            totalRecord: 100
        };
        var searchkey = TSLobsterAPI.Program.RequestQuery("searchkey") || '';
        var status = TSLobsterAPI.Program.RequestQuery("status") || '-1';
        var data = this.dao.getevaluationpage(searchkey, parseInt(status), pageInfo);
        return { data: data, count: pageInfo.totalRecord };
    };
    /**
     * 医生信息界面，显示点赞最多的评价
     */
    tsevaluationController.prototype.getevaluationtopone = function () {
        var doctId = TSLobsterAPI.Program.RequestQuery("doctId");
        var data = this.dao.getevaluationtopone(doctId);
        return { data: data };
    };
    /**
     * 查询医生全部评价
     */
    tsevaluationController.prototype.getevaluationbydoctor = function () {
        var pageInfo = {
            key: "ID desc",
            page: TSLobsterAPI.Program.RequestQuery("page", "1"),
            perPage: TSLobsterAPI.Program.RequestQuery("perPage", "5"),
            totalRecord: 100
        };
        var doctId = TSLobsterAPI.Program.RequestQuery("doctId");
        var data = this.dao.getevaluationbydoctor(doctId, pageInfo);
        return { data: data, count: pageInfo.totalRecord };
    };
    /**
     * 保存回复内容
     */
    tsevaluationController.prototype.savereplycontent = function () {
        var model = JSON.parse(TSLobsterAPI.Program.RequestBody());
        this.dao.savereplycontent(model.ID, model.ReplyContent);
        return { result: true };
    };
    /**
     * 删除回复内容
     */
    tsevaluationController.prototype.deletereplycontent = function () {
        var id = TSLobsterAPI.Program.RequestQuery("ID") || '0';
        this.dao.savereplycontent(id, null);
        return { result: true };
    };
    /**
     * 发布，取消发布
     */
    tsevaluationController.prototype.stopevaluation = function () {
        var id = TSLobsterAPI.Program.RequestQuery("id") || '0';
        var status = TSLobsterAPI.Program.RequestQuery("status") || '0';
        this.dao.stopevaluation(id, status);
        return { result: true };
    };
    /**
     * 更新评价点赞数
     */
    tsevaluationController.prototype.updateevaluationgivecount = function () {
        var id = TSLobsterAPI.Program.RequestQuery("id");
        var givecount = this.dao.updateevaluationgivecount(id);
        return { result: true, givecount: givecount };
    };
    return tsevaluationController;
}());

